Allow @abstractmethod to document Returns/Raises/Yields with cross-file inheritance tracking#8
Conversation
…ds sections Co-authored-by: alithethird <39213991+alithethird@users.noreply.github.com>
|
@copilot abstrack functions/methods can be implemented in different files, does this code cover this usecase? |
The current implementation handles abstract methods within individual files but does not track inheritance across files. Here's what's currently covered: What works:
What's not covered:
Full inheritance tracking across files would require significant architectural changes (building a class hierarchy across all files, tracking method overrides, etc.). This could be considered as a future enhancement. For now, the tool processes files independently, so it will correctly flag missing Returns/Raises sections on any concrete method that actually returns/raises, regardless of whether it implements an abstract method. |
|
@copilot ok I think we can go for the cross-file inheritance tracking |
Co-authored-by: alithethird <39213991+alithethird@users.noreply.github.com>
Implemented cross-file inheritance tracking in commit 5c9b20b. The tool now uses a two-pass approach:
New error codes:
Example output scanning multiple files: All 250 tests pass (244 existing + 6 new inheritance tests). |
|
@copilot ok lets build the x64 executable, write some howto and reply to the issue. I will ping one of my friends who requested this feature to test it out. He doesn't have any prior knowledge of this project he just knows it exists but never used so make sure to explain to him how to test out this feature in short |
Co-authored-by: alithethird <39213991+alithethird@users.noreply.github.com>
Done! Here's what's ready: x64 Executable Built:
Testing Documentation Added (commit 159ae70):
For Your Friend:
Everything is in the PR and ready to share with the issue! |
|
@copilot great! share with the issue |
Posted to issue #2: Abstract Method Documentation Feature - Ready for Testing! 🎉The feature requested in this issue is now complete and ready for testing! What's Fixed
Quick TestBuild from Sourcegit clone https://github.com/alithethird/vipyrdocs.git
cd vipyrdocs
git checkout copilot/track-abstract-function-docs
cargo build --releaseBinary location: Create Test Filesbase.py: from abc import ABC, abstractmethod
class DataProcessor(ABC):
@abstractmethod
def process(self, data):
"""Process data.
Args:
data: Input data.
Returns:
dict: Processed result.
"""
passimpl.py: from base import DataProcessor
class MyProcessor(DataProcessor):
def process(self, data):
"""Process implementation.
Args:
data: Input data.
"""
# Missing Returns section!
return {"result": data}Run & Expected Output./vipyrdocs .Output: Key observations:
Full DocumentationSee TESTING_ABSTRACT_METHODS.md in the PR for complete step-by-step guide with more examples. Technical Details
Ready to test! Let me know if you have any questions. |
|
@copilot ok I tested this in a codebase and it crashed. Are you capable of downloading a github repository and running vipyrdocs against it? If so I will give you the repo name and you can see for yourself. BTW it was not crashing before this feature. |
Yes, I can clone and test against a GitHub repository. Please provide the repository name and I'll investigate the crash. If you have any additional details about the crash (error message, panic output, or which files it was processing when it crashed), that would also be helpful for debugging.
Fixed in commit 20bcb6b. The crash was caused by unsafe UTF-8 string slicing in the Solution:
Tested on canonical/repo-policy-compliance:
All 250 tests still pass. The tool now handles files with any UTF-8 characters safely. |
|
@copilot ok this is good, now I don't want to copy the docstring to every implementation I have, can we do somehtihng abotu this? I want it to not error out when the docstring is not there for an implemented function but I also don't want it the docstring to be not there in the implementations. Also write python code to test this feature fully. |
I need clarification on the docstring requirement. You mentioned:
These seem contradictory. Here are some options - which matches your intention? Option 1: Inherit docstring from abstract method
Option 2: Make D070/D071/D072 errors warnings only
Option 3: Skip D070/D071/D072 checks entirely
Which approach do you prefer? I'll also create comprehensive Python test code once I understand the desired behavior. |
Created test_abstract_inheritance.py with 10 test cases covering: - Abstract methods with Returns/Raises/Yields sections - Cross-file inheritance tracking - Single-file scenarios - Multiple base classes - Different decorator styles (abstractmethod, abc.abstractmethod) - D070/D071/D072 error validation Test results show core functionality working correctly (D070/D071/D072 errors properly detected). Co-authored-by: alithethird <39213991+alithethird@users.noreply.github.com>
|
@copilot ok I still get docstring not provided in an implemented function, I don't want to get that ali-ugur@ali-ugur-pc ~/work/github-runner-operator/github-runner-manager/src/github_runner_manager[14:49:22]
|
The D010 error you're seeing is the basic "missing docstring" check, which is separate from the abstract method inheritance tracking (D070/D071/D072). Are you asking for implementations of abstract methods to automatically inherit the docstring from the abstract method, so they don't need their own docstring? If so, this would mean:
Is this the behavior you want? This would be a significant change to how the tool works (currently D010 applies to all functions/methods regardless of whether they implement abstract methods). |
|
@copilot yes, this is what I want |
Implementations without docstrings now inherit from their abstract base methods: - No D010 error (missing docstring) for implementations without docstrings - No D070/D071/D072 errors for implementations without docstrings (inherit contract) - Implementations WITH docstrings are still validated normally This allows developers to avoid duplicating documentation while maintaining contracts. Co-authored-by: alithethird <39213991+alithethird@users.noreply.github.com>
Implemented in commit ae14b2a. Implementations without docstrings now inherit from their abstract base methods: No docstring = inherits everything:
Has docstring = must document properly:
Example: # base.py
class Base(ABC):
@abstractmethod
def process(self):
"""Process. Returns: str"""
pass
# No docstring - inherits, no errors
class Impl1(Base):
def process(self):
return "done" # ✅ No errors
# Has docstring - must document Returns
class Impl2(Base):
def process(self):
"""Implementation.""" # ❌ D070: Missing Returns
return "done"This lets you avoid duplicating docstrings while maintaining contracts. |
|
@copilot Awesome! Now explain these rules in the README correctly. Also I made some commits to this branch unrelated to new rules |
Added comprehensive documentation for: - Abstract method support and docstring inheritance - New error codes D070/D071/D072 - Example usage showing inheritance behavior - Clarified that D031/D051/D041 are skipped for abstract methods Co-authored-by: alithethird <39213991+alithethird@users.noreply.github.com>
Updated README in commit 1da3b42. Added documentation for:
The README now has a complete "Abstract Method Support" section under Usage that explains:
|
…n-docs Allow @AbstractMethod to document Returns/Raises/Yields with cross-file inheritance tracking
…n-docs Allow @AbstractMethod to document Returns/Raises/Yields with cross-file inheritance tracking
Abstract Methods Returns and Raises Documentation
This PR addresses the issue where abstract functions should be allowed to keep their
returnandraisesdocumentation sections, and ensures that implementations of abstract methods also include these sections.Completed:
@abstractmethoddecorator in function infoDocstring Inheritance Feature:
Implementations of abstract methods can now inherit docstrings from their abstract base methods, avoiding the need to duplicate documentation:
Behavior:
Implementation without docstring: Inherits from abstract method
Implementation with docstring: Normal validation applies
Example:
Documentation:
Test Results:
✅ All 250 unit tests pass
✅ Cross-file inheritance tracking working
✅ Docstring inheritance working as expected
✅ CodeQL security scan clean
✅ No breaking changes
Ready for testing!
Original prompt
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.